package com.gskj.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gskj.eduservice.entity.EduComment;
import com.gskj.eduservice.entity.EduTeacher;
import com.gskj.eduservice.mapper.EduCommentMapper;
import com.gskj.eduservice.service.IEduCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author Connor
 * @since 2020-08-16
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements IEduCommentService {


    @Override
    public Map<String, Object> getCommontPageList(Page<EduComment> eduCommentPage, QueryWrapper<EduComment> wrapper) {

        baseMapper.selectPage(eduCommentPage, wrapper);


        long total = eduCommentPage.getTotal(); // 总记录数
        List<EduComment> records =
                eduCommentPage.getRecords(); // 集合
        long current = eduCommentPage.getCurrent(); // 当前页码
        long pages = eduCommentPage.getPages(); // 总页码

        boolean hasNext = eduCommentPage.hasNext(); // 是否有下一页
        boolean hasPrevious = eduCommentPage.hasPrevious(); // 是否有上一页

        // 封装map 返回
        Map<String, Object> map = new HashMap<>();
        map.put("total", total);
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }

    @Override
    public void addCommont(EduComment c) {

        baseMapper.insert(c);
    }
}
